# Prepend templates
<%= render_templates("src/templates/*") %>
for ZTEMPLATE in ${(k)ZTEMPLATES}; do
  USER_FILE=<%= home %>/.${ZTEMPLATE}
  if [[ -e ${USER_FILE} ]]; then
    USER_FILE=${USER_FILE:A}
    if ERR=$(command mv =(
      print -R ${ZTEMPLATES[${ZTEMPLATE}]}
      cat ${USER_FILE}
    ) ${USER_FILE} 2>&1); then
      print -PR "<%= okay %>Prepended Zim template to %B${USER_FILE}%b"
    else
      print -u2 -PR "%F{red}<%= error %>Error prepending Zim template to %B${USER_FILE}%b%f"$'\n'${ERR}
      return 1
    fi
  else
    if ERR=$(print -R ${ZTEMPLATES[${ZTEMPLATE}]} > ${USER_FILE}); then
      print -PR "<%= okay %>Copied Zim template to %B${USER_FILE}%b"
    else
      print -u2 -PR "%F{red}<%= error %>Error copying Zim template to %B${USER_FILE}%b%f"$'\n'${ERR}
      return 1
    fi
  fi
done
